<template>
	<view class="shoping_box">
		<!-- 商品列表 -->
		<view class="shoping_item" v-for="(item, i) in shopingList" :key="i" @click="gotoGoodsDetail(item)">
			<!-- 左侧图片 -->
			<view class="shoping_img">
				<image :src="item.goods_big_logo || emptyImg" mode="widthFix"></image>
			</view>
			<!-- 右侧内容 -->
			<view class="shoping_content">
				<text class="tit">{{item.goods_name}}</text>
				<text class="price">￥：{{item.goods_price}}元</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				queryObj: {
					query: '',
					cid: '',
					pagenum: 1,
					pagesize: 10
				},
				total: 0,
				shopingList: [],
				emptyImg: '../../static/logo.png',
				isLoading: false
			};
		},
		onLoad(options){
			this.queryObj.query = options.query || ''
			this.queryObj.cid = options.cid || ''
			this.getShopingDetail()
		},
		onReachBottom() {
			if(this.isLoading || this.queryObj.pagenum * this.queryObj.pagesize >= this.queryObj.total) return
			uni.showLoading({
				title:'加载中...',
				mask:false
			})
			this.queryObj.pagenum++
			this.getShopingDetail()
		},
		methods:{
			async getShopingDetail(){
				this.isLoading = true
				const {data: res} = await uni.$http.get('/api/public/v1/goods/search',this.queryObj)
				this.queryObj.total = res.message.total
				this.shopingList = [...this.shopingList,...res.message.goods]
				console.log("shoping详情", res.message);
				uni.hideLoading()
				this.isLoading = false
			},
			gotoGoodsDetail(e){
				uni.navigateTo({
					url: `../../subpkg/goods_detail/goods_detail?goods_id=${e.goods_id}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.shoping_item{
		font-size: 0;
		width: 90%;
		margin: 0 auto 30rpx;
		border-radius: 20rpx;
		background-color: #eee;
		.shoping_img{
			display: inline-block;
			vertical-align: top;
			width: 40%;
			image{
				width: 100%;
				display: block;
				border-radius: 20rpx 0 0 20rpx;
			}
		}
		.shoping_content{
			display: inline-block;
			vertical-align: top;
			width: 60%;
			text{
				display: block;
				font-size: 25rpx;
				padding: 10px 15rpx 0 15rpx;
			}
			.price{margin-top: 40rpx;text-decoration: underline;color: mediumvioletred;}
		}
	}
</style>
